package com.ychs.lawyer.service.impl;

import com.ychs.lawyer.bean.Case;
import com.ychs.lawyer.bean.Lawyer;
import com.ychs.lawyer.bean.User;
import com.ychs.lawyer.mapper.CaseMapper;
import com.ychs.lawyer.mapper.UserMapper;
import com.ychs.lawyer.mapper.LawyerMapper;
import com.ychs.lawyer.service.LawyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: clh
 * @Date: 2024/07/27/23:41
 * @Description:
 */
@Service
public class LawyerServiceImpl implements LawyerService {
    @Autowired
    private LawyerMapper lawyerMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private CaseMapper caseMapper;
    @Autowired
    private BCryptPasswordEncoder passwordEncoder;

    @Override
    public List<Lawyer> getLawyersByCondition(Lawyer lawyer) {
        List<Lawyer> lawyers = lawyerMapper.getLawyersByCondition(lawyer);
        return lawyers;
    }

    @Override
    public int addLawyer(Lawyer lawyer) {
        User user = new User();
        user.setUserId(lawyer.getLawyerId());
        user.setRoleId(1);
        user.setUserName(lawyer.getLawyerName());
        user.setPhoneNumber(lawyer.getPhoneNumber());
        String phoneNumber = user.getPhoneNumber();
        String DefaultPassword = phoneNumber.substring(phoneNumber.length() - 6);
        //加密
        String encode = passwordEncoder.encode(DefaultPassword);
        user.setPassword(encode);
        user.setIsActive(true);

        int i = userMapper.addUser2(user);

        return lawyerMapper.addLawyer(lawyer);
    }

    @Override
    public int editLawyer(Lawyer lawyer) {
        return lawyerMapper.editLawyer(lawyer);
    }

    @Transactional
    @Override
    public int selectCase(String lawyerName) {
        int Casetotal = lawyerMapper.selectCaseToal(lawyerName);
//        lawyerMapper.selectCaseStatus()
//        List<Integer> Total = new ArrayList<>();
//        Total.add(Casetotal);
        return Casetotal;
    }
    /**
     * 查询每个律师下的案件名
     * @param lawyerName
     * @return
     */
    @Override
    public List<Case> selectLawyerName(String lawyerName) {
        return caseMapper.selectLawyerName(lawyerName);
    }

    /**
     * 胜诉
     * @param lawyerName
     * @return
     */
    @Override
    public int selectVictoryCase(String lawyerName) {
      return lawyerMapper.selectVictoryCase(lawyerName);
    }

    /**
     * 败诉
     * @param lawyerName
     * @return
     */
    @Override
    public int selectFaildCase(String lawyerName) {
        return lawyerMapper.selectFaildCase(lawyerName);
    }

    /**
     * 调节
     * @param lawyerName
     * @return
     */
    @Override
    public int selectTalkCase(String lawyerName) {
         return lawyerMapper.selectTalkCase(lawyerName);
    }
}

